package com.gaoding.shared.dict.interceptor;

import com.gaoding.commons.user.User;
import com.gaoding.commons.user.UserUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 用户上下文拦截器
 *
 * @author mobai
 * @since 2021/4/16 11:21
 */
@Configuration
public class UserContextConfiguration implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new UserContextInterceptor());
    }

    public static class UserContextInterceptor implements HandlerInterceptor {
        @Override
        public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
            User user = new User();
            user.setId(0L);
            user.setOrgId(0L);
            UserUtil.setCurrentUser(user);
            return true;
        }
    }
}
